<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>投票表单 - Django网络投票系统</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        /* 基础样式 - 与index.html完全一致 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
            color: #333;
        }
        
        .container {
            width: 100%;
            max-width: 900px;
            background: rgba(255, 255, 255, 0.95);
            border-radius: 20px;
            box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
            overflow: hidden;
        }
        
        header {
            background: linear-gradient(to right, #4b6cb7, #182848);
            color: white;
            padding: 25px 40px;
            text-align: center;
            position: relative;
        }
        
        header h1 {
            font-size: 2.2rem;
            margin-bottom: 10px;
            letter-spacing: 1px;
        }
        
        header p {
            opacity: 0.9;
            font-size: 1.1rem;
        }
        
        .back-btn {
            position: absolute;
            left: 20px;
            top: 50%;
            transform: translateY(-50%);
            background: rgba(255, 255, 255, 0.2);
            border: none;
            color: white;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.3s ease;
        }
        
        .back-btn:hover {
            background: rgba(255, 255, 255, 0.3);
            transform: translateY(-50%) scale(1.1);
        }
        
        .content {
            padding: 40px;
        }
        
        .card {
            background: white;
            border-radius: 15px;
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
            padding: 30px;
            margin-bottom: 30px;
            transition: transform 0.3s ease;
        }
        
        .card:hover {
            transform: translateY(-5px);
        }
        
        /* Detail页特有样式 */
        .question-title {
            color: #2c3e50;
            margin-bottom: 30px;
            padding-bottom: 15px;
            border-bottom: 2px solid #e0e6ed;
            font-size: 1.8rem;
            text-align: center;
        }
        
        .error-message {
            background: #ffebee;
            color: #c62828;
            padding: 15px;
            border-radius: 10px;
            margin-bottom: 25px;
            display: flex;
            align-items: center;
            border-left: 4px solid #c62828;
        }
        
        .error-message i {
            margin-right: 10px;
            font-size: 1.5rem;
        }
        
        .choices-container {
            margin: 25px 0;
        }
        
        .choice-item {
            display: flex;
            align-items: center;
            padding: 18px 20px;
            margin-bottom: 15px;
            background: #f8f9fa;
            border-radius: 12px;
            transition: all 0.3s ease;
            cursor: pointer;
            border: 2px solid #e0e6ed;
        }
        
        .choice-item:hover {
            background: #e9f7fe;
            border-color: #3498db;
            transform: translateX(5px);
        }
        
        .choice-item.selected {
            background: #e3f2fd;
            border-color: #2196f3;
            box-shadow: 0 5px 15px rgba(33, 150, 243, 0.15);
        }
        
        input[type="radio"] {
            display: none;
        }
        
        .custom-radio {
            width: 24px;
            height: 24px;
            border: 2px solid #90a4ae;
            border-radius: 50%;
            margin-right: 18px;
            position: relative;
            transition: all 0.2s ease;
        }
        
        input[type="radio"]:checked + .custom-radio {
            border-color: #2196f3;
            background: #2196f3;
        }
        
        input[type="radio"]:checked + .custom-radio::after {
            content: '';
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 12px;
            height: 12px;
            background: white;
            border-radius: 50%;
        }
        
        .choice-label {
            font-size: 1.2rem;
            color: #37474f;
            font-weight: 500;
            flex-grow: 1;
        }
        
        .vote-btn {
            display: block;
            width: 100%;
            padding: 16px;
            background: linear-gradient(to right, #4b6cb7, #182848);
            color: white;
            border: none;
            border-radius: 12px;
            font-size: 1.2rem;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-top: 20px;
            box-shadow: 0 5px 15px rgba(75, 108, 183, 0.3);
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .vote-btn i {
            margin-right: 10px;
        }
        
        .vote-btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 20px rgba(75, 108, 183, 0.4);
        }
        
        .stats-bar {
            display: flex;
            justify-content: space-between;
            margin-top: 25px;
            padding-top: 20px;
            border-top: 1px solid #eee;
            color: #7f8c8d;
            font-size: 0.95rem;
        }
        
        .participants {
            display: flex;
            align-items: center;
        }
        
        .participants i {
            margin-right: 8px;
            color: #4b6cb7;
        }
        
        .question-id {
            background: #f0f4f8;
            padding: 5px 12px;
            border-radius: 20px;
        }
        
        footer {
            text-align: center;
            padding: 25px;
            color: #7f8c8d;
            background: #f8f9fa;
            border-top: 1px solid #e0e6ed;
            font-size: 0.95rem;
        }
        
        /* 响应式设计 - 与index.html一致 */
        @media (max-width: 768px) {
            .content {
                padding: 25px;
            }
            
            header h1 {
                font-size: 1.8rem;
            }
            
            .question-title {
                font-size: 1.5rem;
            }
            
            .choice-item {
                padding: 15px;
                flex-direction: column;
                align-items: flex-start;
            }
            
            .choice-label {
                font-size: 1.1rem;
                margin-top: 10px;
            }
            
            .custom-radio {
                margin-right: 0;
                margin-bottom: 10px;
            }
            
            .vote-btn {
                padding: 14px;
                font-size: 1.1rem;
            }
            
            .stats-bar {
                flex-direction: column;
                gap: 10px;
                align-items: flex-start;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <a href="{% url 'polls:index' %}" class="back-btn">
                <i class="fas fa-arrow-left"></i>
            </a>
            <h1><i class="fas fa-vote-yea"></i> 投票表单</h1>
            <p>请选择您的答案并提交</p>
        </header>
        
        <div class="content">
            <form action="{% url 'polls:vote' question.id %}" method="post" id="voteForm">
                {% csrf_token %}
                <div class="card">
                    <h2 class="question-title">
                        <i class="fas fa-question-circle"></i> 
                        {{ question.question_text }}
                    </h2>
                    
                    {% if error_message %}
                    <div class="error-message">
                        <i class="fas fa-exclamation-circle"></i>
                        <strong>{{ error_message }}</strong>
                    </div>
                    {% endif %}
                    
                    <div class="choices-container">
                        {% for choice in question.choice_set.all %}
                        <label class="choice-item">
                            <input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}">
                            <span class="custom-radio"></span>
                            <span class="choice-label">{{ choice.choice_text }}</span>
                        </label>
                        {% endfor %}
                    </div>
                    
                    <button type="submit" class="vote-btn">
                        <i class="fas fa-paper-plane"></i> 提交投票
                    </button>
                    
                    <div class="stats-bar">
                        <div class="participants">
                            <i class="fas fa-users"></i> 已有 {{ question.total_votes }} 人参与投票
                        </div>
                        <div class="question-id">
                            问题 ID: #{{ question.id }}
                        </div>
                    </div>
                </div>
            </form>
        </div>
        
        <footer>
            <p>© 2023 Django网络投票系统 | 请谨慎选择您的答案 | 投票后不可更改</p>
        </footer>
    </div>

    <script>
        // 表单提交处理
        document.getElementById('voteForm').addEventListener('submit', function(e) {
            // 检查是否有选择
            const selected = document.querySelector('input[name="choice"]:checked');
            const errorMessage = document.querySelector('.error-message');
            
            if (!selected && errorMessage) {
                errorMessage.style.display = 'flex';
                e.preventDefault();
                return;
            }
            
            // 如果已经处理过提交，不再重复提交
            if (this.dataset.submitted) {
                e.preventDefault();
                return;
            }
            
            // 标记表单已提交
            this.dataset.submitted = 'true';
            
            // 显示加载状态
            const submitBtn = this.querySelector('button[type="submit"]');
            const originalText = submitBtn.innerHTML;
            submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> 提交中...';
            submitBtn.disabled = true;
        });
        
        // 添加选择效果
        const choiceItems = document.querySelectorAll('.choice-item');
        choiceItems.forEach(item => {
            item.addEventListener('click', function() {
                // 移除其他选项的选择状态
                choiceItems.forEach(i => i.classList.remove('selected'));
                
                // 添加当前选项的选择状态
                this.classList.add('selected');
                
                // 隐藏错误消息
                const errorMessage = document.querySelector('.error-message');
                if (errorMessage) {
                    errorMessage.style.display = 'none';
                }
                
                // 触发radio的选中状态
                const radio = this.querySelector('input[type="radio"]');
                radio.checked = true;
            });
        });
        
        // 初始化已选中的选项
        document.addEventListener('DOMContentLoaded', function() {
            const selectedRadio = document.querySelector('input[name="choice"]:checked');
            if (selectedRadio) {
                selectedRadio.closest('.choice-item').classList.add('selected');
            }
        });
    </script>
</body>
</html>